package com.yxy.mapper;

import com.github.pagehelper.Page;
import com.yxy.pojo.dto.RoutePageQueryDTO;
import com.yxy.pojo.entity.Route;
import com.yxy.pojo.entity.Geography;
import com.yxy.pojo.entity.RoutePraise;
import com.yxy.pojo.vo.RoutePageQueryVO;
import com.yxy.pojo.vo.RoutePraisePageQueryVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface RouteMapper {
    /**
     * 查询所有地理信息
     * @return
     */
    @Select("select * from geography")
    List<Geography> selectAllGeography();

    /**
     * 分页查询
     * @param routePageQueryDTO
     * @return
     */
    Page<RoutePageQueryVO> pageQuery(RoutePageQueryDTO routePageQueryDTO);

    /**
     * 添加
     * @param route
     */
    void insert(Route route);

    /**
     * 批量删除
     * @param ids
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 修改
     * @param route
     */
    void update(Route route);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from route where id = #{id}")
    Route selectById(int id);

    /**
     * 修改浏览量
     * @param id
     * @param views
     */
    @Update("update route set views = #{views} where id = #{id}")
    void addRouteViews(int id, int views);

    /**
     * 判断是否点赞
     * @param userId
     * @param routeId
     * @return
     */
    @Select("select * from route_praise where route_id = #{routeId} and user_id = #{userId}")
    RoutePraise isPraise(int userId, int routeId);

    /**
     * 添加点赞
     * @param build
     */
    void addPraise(RoutePraise build);

    /**
     * 修改点赞
     * @param build
     */
    @Update("update route_praise set is_praise = #{isPraise} where user_id = #{userId} and route_id = #{routeId}")
    void updatePraise(RoutePraise build);

    /**
     * 获取浏览量
     * @return
     */
    @Select("select views from route")
    List<Integer> getViews();

    /**
     * 批量删除点赞
     * @param ids
     */
    void deletePraiseByIds(List<Integer> ids);

    /**
     * 分页查询点赞
     * @param routePageQueryDTO
     * @return
     */
    @Select("select * from route_praise where user_id = #{userId} and is_praise = 1")
    Page<RoutePraisePageQueryVO> pageQueryRoutePraise(RoutePageQueryDTO routePageQueryDTO);
}
